//
//  ChatRecodeTableViewCell.m
//  AAIM
//
//  Created by 远的小布丁 on 2020/1/11.
//  Copyright © 2020 AAIM. All rights reserved.
//

#import "ChatRecodeTableViewCell.h"

@implementation ChatRecodeTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setShowUI{
    [self.contentView addSubview:self.headImageView];
    [self.contentView addSubview:self.timeLbl];
    [self.contentView addSubview:self.titleLbl];
    [self.contentView addSubview:self.nickNameLbl];
    [self.contentView addSubview:self.contentLbl];

    [_headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(15);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(36, 36));
    }];
    [_timeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headImageView.mas_top);
        make.right.equalTo(self.contentView.mas_right).offset(-15);
        make.size.mas_equalTo(CGSizeMake(90, 15));
    }];
    [_titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImageView.mas_right).offset(8);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.right.equalTo(self.timeLbl.mas_left).offset(-15);
    }];
    [_nickNameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImageView.mas_right).offset(8);
        make.top.equalTo(self.headImageView.mas_top);
        make.right.equalTo(self.timeLbl.mas_left).offset(-15);
    }];
    [_contentLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImageView.mas_right).offset(8);
        make.top.equalTo(self.nickNameLbl.mas_bottom);
        make.right.equalTo(self.contentView.mas_right).offset(-15);
    }];
}

- (void)setModel:(BTMessageModel *)model{
    _model = model;
//    NSData * data;
    KWeakSelf;
    if ([model.head containsString:@"http"]) {
//        data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",model.head]]];
        [_headImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",model.head]] placeholderImage:[UIImage imageNamed:@"bg_pyqtx"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                   
                   weakSelf.headImageView.image = image;
                   }];
    }else{
//         data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage,model.head]]];
        [_headImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage,model.head]] placeholderImage:[UIImage imageNamed:@"bg_pyqtx"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                  
                   weakSelf.headImageView.image = image;
                   }];
    }

 
//    _headImageView.image = [UIImage imageWithData:data];
    _nickNameLbl.text = model.nickname;
    _contentLbl.text = model.msg;
    _timeLbl.text = [NSString stringWithFormat:@"%@",[CommonTools changeTimesTamp:model.timestamp]];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (UIImageView *)headImageView{
    if (!_headImageView) {
        _headImageView = [[UIImageView alloc]init];
        _headImageView.layer.cornerRadius = 5;
        _headImageView.layer.masksToBounds = YES;
        _headImageView.image = [UIImage imageNamed:@"我的-头像"];
    }
    return _headImageView;
}

-(UILabel *)nickNameLbl{
    if (!_nickNameLbl) {
        _nickNameLbl = [[UILabel alloc]init];
        _nickNameLbl.font = kMainFont(12);
        _nickNameLbl.textColor = KHEXCOLOR(@"#AFAFAF");
        _nickNameLbl.text = @"钢铁女孩";
    }
    return _nickNameLbl;
}

-(UILabel *)contentLbl{
    if (!_contentLbl) {
        _contentLbl = [[UILabel alloc]init];
        _contentLbl.font = kMainFont(15);
        _contentLbl.textColor = [UIColor blackColor];
        _contentLbl.text = @"今天去吃大餐呀！很美味可口的，很久没去吃了呢，一起去吧！下班后就去，吃完再去逛一逛！";
    }
    return _contentLbl;
}

- (UILabel *)titleLbl{
    if (!_titleLbl) {
        _titleLbl = [[UILabel alloc]init];
        _titleLbl.font = kFont(17);
        _titleLbl.hidden = YES;
        _titleLbl.textColor = [UIColor blackColor];
        _titleLbl.text = @"“钢铁女孩”的记录";
    }
    return _titleLbl;
}

-(UILabel *)timeLbl{
    if (!_timeLbl) {
        _timeLbl = [[UILabel alloc]init];
        _timeLbl.font = kFont(13);
        _timeLbl.textColor = KHEXCOLOR(@"#AFAFAF");
        _timeLbl.text = @"2020/01/12";
        _timeLbl.textAlignment = NSTextAlignmentRight;
    }
    return _timeLbl;
}

@end
